home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-11-24 | 5.4 KB | 194 lines | [TEXT/MPS ] |
- # MakePPCCodeRsrc - Create a PowerPC code resource from a PEF file.
- #
- # Copyright © 1998, Apple Computer, Inc., All Rights Reserved
- #
- # History:
- #
- # 11/10/98 cae v1.0d1 Initial version
- # 11/24/98 cae v1.0d2 Added "Set Echo 0" at start of script
- #
- # Usage:
- #
- # MakePPCCodeRsrc inputfile -rt restype=id [-rn resname] [-ra attributes] [-o outputfile] [-a[ppend]] [-ov] [-rawpef] [-c creator] [-t filetype]
- # inputfile # a file containing a single PowerPC PEF container in the data fork
- # -rt restype=id # specify the resource type and ID
- # -rn resname # specify the resource name
- # -ra attributes # specify the resource attributes
- # -o outputfile # specify the output file (default: <inputfilename>.rsrc)
- # -a[ppend] # append the resource to the output file
- # -ov # ok to overwrite protected resource when appending
- # -rawpef # don't add a resource descriptor
- # -c creator # set the output file creator
- # -t filetype # set the output file type
- #
-
- Set Echo 0
-
- Set Syntax "inputfile -rt restype=id [-rn resname] [-ra attributes] [-o outputfile] [-a[ppend]] [-ov] [-rawpef] [-c creator] [-t filetype]"
-
- Set Error 0
-
- Set Cmd "{0}"
- Set InputFile ""
- Set OutputFile ""
- Set ResType ""
- Set ResID ""
- Set ResName ""
- Set ResAttr 0
- Set CreatorOpt ""
- Set FileTypeOpt ""
- Set AppendOpt ""
- Set OverwriteOpt ""
- Set DoRawPEF 0
-
- # Parse the command line.
- loop
- break if "{#}" < 1
-
- # Check for the -rt option.
- If "{1}" == "-rt"
- (Evaluate "{2}" =~ /(≈)®1=(≈)®2/) >Dev:Null
- Set ResType "{®1}"
- Set ResID "{®2}"
- shift
-
- # Check for the -rn option.
- Else If "{1}" == "-rn"
- Set ResName "{2}"
- shift
-
- # Check for the -ra option.
- Else If "{1}" == "-ra"
- Set ResAttr "{2}"
- shift
-
- # Check for the -o option.
- Else If "{1}" == "-o"
- Set OutputFile "{2}"
- shift
-
- # Check for the -a[ppend] option.
- Else If "{1}" == "-a" || "{1}" == "-append"
- Set AppendOpt "-a"
-
- # Check for the -ov option.
- Else If "{1}" == "-ov"
- Set OverwriteOpt "-ov"
-
- # Check for the -rawpef option.
- Else If "{1}" == "-rawpef"
- Set DoRawPEF 1
-
- # Check for the -c option.
- Else If "{1}" == "-c"
- Set CreatorOpt "-c ∂"'{2}'∂""
- shift
-
- # Check for the -t option.
- Else If "{1}" == "-t"
- Set FileTypeOpt "-t ∂"'{2}'∂""
- shift
-
- # Found an unknown option.
- Else If "{1}" =~ /-≈/ || "{1}" == -
- Echo "### {Cmd} - ∂"{1}∂" is not an option."
- Set Error 1
-
- # Found the input file.
- Else
- If "{InputFile}" == ""
- Set InputFile "{1}"
- Else
- Echo "### {Cmd} - More than one input file specified."
- Set Error 1
- End
- End
-
- shift
- End > Dev:StdErr
-
- # Make sure an input file was specified.
- If "{InputFile}" == ""
- Echo "### {Cmd} - No input file specified."
- Set Error 1
- End > Dev:StdErr
-
- # Make sure -rt was specified.
- If ("{ResType}" == "" || "{ResID}" == "")
- Echo "### {Cmd} - Must specify a resource type and ID using the -rt option."
- Set Error 1
- End > Dev:StdErr
-
- # Were there any syntax errors?
- If {Error}
- Echo "# Usage - {Cmd} {Syntax}"
- Exit {Error}
- End > Dev:StdErr
-
- # If -o wasn't specified, use the default output file name.
- If "{OutputFile}" == ""
- Set OutputFile "{InputFile}".rsrc
- End
-
- Set Exit 0
-
- # Make sure the output file name isn't too long.
- Unset {®1}
- (Evaluate "{OutputFile}" =~ /(≈:)*(≈)®1/) ∑ Dev:Null
- Set TempCount `Echo -n "{®1}" | Count -c`
- If {TempCount} > 31
- Echo "# {0} - Output file name “{OutputFile}” is too long."
- Exit 2
- End > Dev:StdErr
-
- # Make sure the input file is a valid PEF file.
- DumpPEF "{InputFile}" -c ∑ Dev:Null
- If {status} != 0
- Echo "# {0} - “{InputFile}” doesn't appear to be a valid PEF file."
- Exit 2
- End > Dev:StdErr
-
- # Dump the input file's 'cfrg' resource.
- DumpPEF "{InputFile}" -do r > "{TempFolder}MakePPCCodeRsrc_Temp"
-
- # Make sure there is a single PEF Container in the data fork of the input file.
- Set TempCount `StreamEdit "{TempFolder}MakePPCCodeRsrc_Temp" -d -e '/kOnDiskFlat/ Print' | Count -l`
- If {TempCount} == 0
- Echo "# {0} - No PEF Containers found in the data fork of “{InputFile}”."
- Delete -i "{TempFolder}MakePPCCodeRsrc_Temp"
- Exit 2
- Else If {TempCount} != 1
- Echo "# {0} - More than one PEF Container found in the data fork of “{InputFile}”."
- Delete -i "{TempFolder}MakePPCCodeRsrc_Temp"
- Exit 2
- End > Dev:StdErr
-
- # Make sure the PEF Container is a PowerPC container.
- Set TempCount `StreamEdit "{TempFolder}MakePPCCodeRsrc_Temp" -d -e '/kPowerPC/ Print' | Count -l`
- If {TempCount} != 1
- Echo "# {0} - No PowerPC PEF Containers found in the data fork of “{InputFile}”."
- Delete -i "{TempFolder}MakePPCCodeRsrc_Temp"
- Exit 2
- End > Dev:StdErr
-
- # Create the code resource.
- If {DoRawPEF}
- # Write the PEF container out to the specified resource.
- Echo "read '{ResType}' ({ResID},∂"{ResName}∂",{ResAttr}) ∂"{InputFile}∂";" | Rez -o "{OutputFile}" {AppendOpt} {OverwriteOpt} {CreatorOpt} {FileTypeOpt}
- Else
- # Write a routine descriptor followed by the PEF container out to the specified resource.
- Echo "#include ∂"MixedMode.r∂"" > "{TempFolder}MakePPCCodeRsrc_Temp"
- Echo "type '{ResType}' as 'rdes';" >> "{TempFolder}MakePPCCodeRsrc_Temp"
- Echo "resource '{ResType}' ({ResID},∂"{ResName}∂",{ResAttr}) ∂{" >> "{TempFolder}MakePPCCodeRsrc_Temp"
- Echo "1," >> "{TempFolder}MakePPCCodeRsrc_Temp"
- Echo "$$Read (∂"{InputFile}∂")" >> "{TempFolder}MakePPCCodeRsrc_Temp"
- Echo "∂};" >> "{TempFolder}MakePPCCodeRsrc_Temp"
- Rez "{TempFolder}MakePPCCodeRsrc_Temp" -s ":" -o "{OutputFile}" {AppendOpt} {OverwriteOpt} {CreatorOpt} {FileTypeOpt}
- End
-
- # Delete the temp file.
- Delete -i "{TempFolder}MakePPCCodeRsrc_Temp"
-
- Exit {Status}
-
-